package com.classroom.smart.service;

import com.classroom.smart.mapper.ComplainMapper;
import com.classroom.smart.pojo.Complain;
import com.classroom.smart.pojo.ComplainExample;
import com.classroom.smart.pojo.Feedback;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther:YouGuoyun
 * @Title:leetcode
 * @Date:Create in 2023/2/22 18:39
 **/
@Service
public class ComplainService {

    @Autowired
    private ComplainMapper complainMapper;

    @Transactional
    public void insert(Complain complain) {
        complainMapper.insert(complain);
    }

    //查找所有未处理投诉
    public List<Complain> viewAllNotProcess(int current,int status){
        ComplainExample complainExample = new ComplainExample();
        ComplainExample.Criteria criteria = complainExample.createCriteria();
        criteria.andStatusEqualTo(status);
        PageHelper.startPage(current,3);
        List<Complain> list = complainMapper.selectByExample(complainExample);
        return list;
    }

    //删除
    public boolean deleteComplain(int id){
        int i = complainMapper.deleteByPrimaryKey(id);
        return i>0;
    }

    //获取要更新的信息
    public Complain getUpdateComplain(int id){
        Complain complain = complainMapper.selectByPrimaryKey(id);
        return complain;
    }

    //更新
    public boolean updateComplain(Complain complain){
        int i = complainMapper.updateByPrimaryKey(complain);
        return i>0;
    }

    // 搜索
    public List<Complain> selectCompains(int current,String query,int complainStatus){
        ComplainExample complainExample = new ComplainExample();
        ComplainExample.Criteria criteria = complainExample.createCriteria();
        criteria.andComplainTypeLike("%" + query + "%");
        criteria.andStatusEqualTo(complainStatus);
        PageHelper.startPage(current,3);
        List<Complain> list = complainMapper.selectByExample(complainExample);
        return list;
    }
}
